package com.saikei.demoapp

import android.util.Log
import android.view.View
import android.widget.TextView
import com.saikei.demoapp.base.BaseInitVMActivity
import com.saikei.demoapp.databinding.ActivityMainBinding
import com.saikei.demoapp.titlebar.statusbar.StatusBarUtils
import com.saikei.demoapp.titlebar.widget.CommonTitleBar
import kotlinx.coroutines.async
import kotlinx.coroutines.delay

class MainActivity : BaseInitVMActivity<ActivityMainBinding, MainVm>() {

    override fun initView() {
        val findViewById = findViewById<CommonTitleBar>(R.id.title_bar)
        findViewById.checkStatusBarPadding(false)
    }

    override fun initData() {
        mViewModel.findAllUser()
    }

    fun onClickInsertUser(view: View) {
        mViewModel.insertUser()

    }

    fun onClickUpSertUser(view: View) {
        mViewModel.mInput.value?.let {
            mViewModel.upsert(it.toInt())
        }
    }

    fun onClickDeleteUser(view: View) {
        mViewModel.mInput.value?.let {
            mViewModel.deleteUserWithBook(it.toInt())
        }
    }

    fun onClickInsertBook(view: View) {
        mViewModel.mInput.value?.let {
            mViewModel.insertUserBook(it.toInt())
        } ?: mViewModel.insertUserBook(null)
    }

    fun onClickFindUserWithBook(view: View){
        mViewModel.mInput.value?.let {
            mViewModel.findUserBookList(it.toInt())
        } ?: mViewModel.findAllUser()
    }

    override fun initObserve() {
    }

    override fun getVmBr(): Int {
        return BR.vm
    }

    override fun getPageBr(): Int {
        return BR.page
    }

}